cp.logic = {};
cp.logic = function() {
	disableNextPrevBtn();
	cp.util.loading(true);
	setNextPrevBtnPosition();
	
	function getBatch(callContext) {
		var url = cp.DOMAIN_URL;
        cp.util.ajaxCall(url,processVideoXml,this);		
	}
	
	function processVideoXml(data,vthis)
	{
		$("#logger").html($("#ires",data).html());
	}
	
	//Start - Functions to control Next and Prev button style and functions
	function setNextPrevBtnPosition()
	{
		$("#next").css("left",cp.winW - 270);
		$("#next").css("top",15);
		
		$("#prev").css("left",cp.winW - 400);
		$("#prev").css("top",15);
	};
	
	var isNextPrevBtnEnabled = false;
	function disableNextPrevBtn()
	{
		isNextPrevBtnEnabled = false;
	};
	function enableNextPrevBtn()
	{
		isNextPrevBtnEnabled = true;
	};
	
	$("#next").click(function() {
		goToNext();
	});
	$("#prev").click(function() {
		goToPrev();
	});
	
	function goToNext()
	{
		if(isNextPrevBtnEnabled){ getBatch(cp.BATCH_RIGHT_STR);};
	};

	function goToPrev()
	{
		if(isNextPrevBtnEnabled){ getBatch(cp.BATCH_LEFT_STR);};
	};
	
	$(window).keydown(function(e) {
	    switch (e.keyCode) {
	    case 37:
	        goToPrev();
	        return true;
	    case 39:
	    	goToNext();
	        return true;
	    }
	    return; 
	});
	//End - Functions to control Next and Prev button style and functions
	
	$("#trendCountry").change(function() {
		var userCountry = $("#trendCountry").val();
		if (cp.USER_COUNTRY != userCountry)
		{
			cp.USER_COUNTRY = userCountry;
			cp.util.setCookie("USER_COUNTRY",cp.USER_COUNTRY,1578449050);
			getBatch(cp.BATCH_START_STR_CH_COUNTRY);
		}
	});
	
	$("input[name=lightSwitch]:radio").change(function() {
		var lightSwitch = $("input[name=lightSwitch]:checked").val();
		cp.util.lights(lightSwitch);
	});

	cp.util.getCookie("USER_COUNTRY",startMusic);
	function startMusic(userCountry){
		cp.USER_COUNTRY = userCountry;
	    $("#trendCountry").val(userCountry);
		getBatch(cp.BATCH_START_STR);
	}
};

cp.logic(); 


